package com.yulan.backTrack;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * 面试题 08.04. 幂集
 */
public class LeetCode_08_04 {
    List<List<Integer> > ans = new ArrayList<>();

    public List<List<Integer>> subsets(int[] nums) {
        backTrack(new ArrayList<>(), nums,0);
        return ans;
    }

    public void backTrack(List<Integer> list, int[] arr, int index){
        ans.add(new ArrayList<>(list));
        for(int i = index; i<arr.length; i++){
            list.add(arr[i]);
            backTrack(list,arr,i+1);
            list.remove(list.size()-1);
        }
    }

    @Test
    public void test(){
        int[] arr = {1,2,3};
        for(List<Integer> list : subsets(arr)){
            System.out.println(list);
        }
    }
}
